package com.bnlr.lrparking.appui.search;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.bnlr.lrparking.appui.stall.StallBegRentBuy;
import com.bnlr.lrparking.constant.LrConstant;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.bnlr.lrparking.app.Application;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.adapter.RentBuyAdapter;
import com.bnlr.lrparking.adapter.StallPriceAdapter;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.app.AppConfig;
import com.bnlr.lrparking.constant.IntentConstant;
import com.bnlr.lrparking.model.AddStallTypeBean;
import com.bnlr.lrparking.model.CarPlaceTypeMode;
import com.bnlr.lrparking.model.ConditionBean;
import com.bnlr.lrparking.model.SpacePriceFilterM;
import com.bnlr.lrparking.model.StallListBean;
import com.bnlr.lrparking.appui.publish.PublishBegActivity;
import com.bnlr.lrparking.constant.Urls;
import com.bnlr.lrparking.appui.carport.filtrate.FiltrateBean;
import com.bnlr.lrparking.appui.carport.filtrate.FiltrateConditionAdapter;
import com.bnlr.lrparking.appui.carport.filtrate.FiltrateConditionBean;
import com.bnlr.lrparking.view.ConditionPopup;
import com.bnlr.lrparking.widget.popcity.CityBean;
import com.bnlr.lrparking.widget.popcity.PopChoseCityAdapter;
import com.bnlr.lrparking.widget.popcity.PopCityJson;
import com.bnlr.lrparking.widget.popcity.PopStallAdapter;
import com.bnlr.lrparking.widget.popcity.PopupCheckBox;
import com.bnlr.lrparking.widget.refresh.RefreshHolderUtil;
import com.bnlr.lrparking.widget.refresh.XRefreshLayout;
import com.bnlr.nohttp.CallServer;
import com.bnlr.nohttp.CustomHttpListener;
import com.bnlr.nohttp.CustomJavaHttpListener;
import com.bnlr.nohttp.HttpListener;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.Response;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 求租求购列表
 * @author hp
 * @date 2017/10/10
 */

public class RentBuyStallActivity extends BaseActivity{

    private Unbinder unbinder;
    @BindView(R.id.check_city)
    PopupCheckBox check_city;
    @BindView(R.id.check_price)
    PopupCheckBox check_price;
    @BindView(R.id.check_type)
    PopupCheckBox check_type;
    @BindView(R.id.swipe_rent_buy)
    XRefreshLayout swipeRefreshLayout;
    @BindView(R.id.recy_rentbuy)
    RecyclerView recy_rentbuy;
    @BindView(R.id.no_data)
    RelativeLayout empty;
    @BindView(R.id.et_title_search)
    TextView et_title_search;
    @BindView(R.id.tv_publish)
    TextView tvPublish;
    @BindView(R.id.tv_condition)
    TextView tvCondition;
    private RentBuyAdapter adapter;
    private List<StallListBean.DataBean> list=new ArrayList<>();

    private RecyclerView rvCity;
    private RecyclerView rvArea;
    private PopChoseCityAdapter adapter1;
    private PopChoseCityAdapter adapter2;
    private  List<CityBean> cityBeen= new ArrayList<>();
    private List<List<CityBean>> areaBeen= new ArrayList<>();
    private List<CityBean> selectOfCity = new ArrayList<>();
    private int selectCityId = 370200;
    private ListView rv_stall_chuzu_list;
    private List<SpacePriceFilterM.DataBean> strstallprice=new ArrayList<>();
    private StallPriceAdapter stallpriceAdapter;

    private PopStallAdapter popStallAdapter1;
    private PopStallAdapter popStallAdapter2;
    private List<ArrayList<CarPlaceTypeMode>> carType2 = new ArrayList<>();
    private List<CarPlaceTypeMode> carType1 = new ArrayList<>();
    private List<CarPlaceTypeMode> selectcarType = new ArrayList<>();
    //查询参数初始化
    private int currentPage = 1;
    private String dealType = "20";
    private int areaId = 0;
    private int orderByWay = 1;
    private String keyWords = "";
    private int spaceType = 0;
    private boolean isCity = true;
    private int PriceID=0;//价格下限
//    private String maxPrice = "0";//价格上限
   private List<FiltrateConditionBean> filtrateData = new ArrayList<>();
    private FiltrateConditionAdapter filtrateAdapter;
    private Map paramsMap = new HashMap();
    private Map<String,Integer> tagMap = new HashMap<>();
    private static final int REQUEST_SEARCH_CODE = 1600;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rentbuystall);
        unbinder = ButterKnife.bind(this);
        initView();
    }

    private void initView(){

        check_city.setText(AppConfig.getInstance().getString("strCity","郑州市"));
        getCityList();
       // getCarPlaceType();
        getConditionLimit();
        Intent intent=getIntent();
        dealType=intent.getStringExtra("dealType");
        getSpacePriceFilter(dealType);
        keyWords = intent.getStringExtra(IntentConstant.INTENT_STALL_DEAL_SEARCH);
        if (TextUtils.isEmpty(keyWords)) {
            keyWords = "";
            if (dealType.equals("20")) {
                et_title_search.setHint("搜索求租车位");
            } else {
                et_title_search.setHint("搜索求购车位");
            }
        } else {
            et_title_search.setText(keyWords);
        }

        recy_rentbuy.setLayoutManager(new LinearLayoutManager(this));
        swipeRefreshLayout.setRefreshViewHolder(RefreshHolderUtil.getRefreshHolder(this));
        swipeRefreshLayout.setDelegate(new XRefreshLayout.BGARefreshLayoutDelegate() {
            @Override
            public void onBGARefreshLayoutBeginRefreshing(XRefreshLayout refreshLayout) {
                currentPage = 1;
                sendRequest(PriceID);
            }

            @Override
            public boolean onBGARefreshLayoutBeginLoadingMore(XRefreshLayout refreshLayout) {
                return false;
            }

        });
        swipeRefreshLayout.beginRefreshing();
        adapter = new RentBuyAdapter(list);
        recy_rentbuy.setAdapter(adapter);
        adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                currentPage ++;
                sendRequest(PriceID);
            }
        },recy_rentbuy);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(RentBuyStallActivity.this, StallBegRentBuy.class);
                intent.putExtra("stall_id",list.get(position).getId());
                startActivity(intent);
            }
        });
        tvCondition.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View view = View.inflate(RentBuyStallActivity.this,R.layout.popup_condition_layout,null);
                RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv_condition);
                recyclerView.setLayoutManager(new GridLayoutManager(RentBuyStallActivity.this,3));
                final ConditionPopup popup = new ConditionPopup(RentBuyStallActivity.this,view);
                filtrateAdapter = new FiltrateConditionAdapter(filtrateData,tagMap);
                recyclerView.setAdapter(filtrateAdapter);
                TextView sure = (TextView) view.findViewById(R.id.tv_condition_complete);
                TextView clear = (TextView) view.findViewById(R.id.tv_condition_clear);
                popup.show();
                sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        tagMap = filtrateAdapter.getMap();
                        popup.hide();
                        Map map = filtrateAdapter.getParams();
                        if (map.size() > 0) {
                            paramsMap = map;
                        } else {
                            paramsMap.clear();
                        }
                        currentPage = 1;
                        sendRequest(PriceID);
                    }
                });
                clear.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        tagMap.clear();
                        for (int i = 0; i < filtrateData.size(); i++) {
                            if (!filtrateData.get(i).isHeader) {
                                filtrateData.get(i).t.setSelected(false);
                            }
                        }
                        filtrateAdapter.notifyDataSetChanged();
                        currentPage = 1;
                        paramsMap.clear();
                        sendRequest(PriceID);
                    }
                });

            }
        });


    }
    @OnClick({R.id.stall_search,R.id.iv_back,R.id.tv_publish})
   public void rentOnclick (View view) {
       switch (view.getId()) {
           case R.id.stall_search:
               Intent intent = new Intent(this,SeachActiity.class);
               intent.putExtra("dealType",dealType);
               intent.putExtra(IntentConstant.INTENT_STALL_DEAL_SEARCH,keyWords);
               startActivityForResult(intent,REQUEST_SEARCH_CODE);
               break;
           case R.id.iv_back:
               finish();
               break;
           case R.id.tv_publish:
               if ("20".equals(dealType)) {
                   startActivity(new Intent(this, PublishBegActivity.class)
                           .putExtra("publish_tag",3));
               } else if ("21".equals(dealType)) {
                   startActivity(new Intent(this, PublishBegActivity.class)
                           .putExtra("publish_tag",4));
               }
               break;
           default:
               break;
       }
   }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        if (requestCode == REQUEST_SEARCH_CODE && resultCode == IntentConstant.SEARCH_RESULT_CODE) {
            keyWords = data.getStringExtra(IntentConstant.INTENT_STALL_DEAL_SEARCH);
            if (TextUtils.isEmpty(keyWords)) {
                keyWords = "";
                if (dealType.equals("20")) {
                    et_title_search.setHint("搜索求租车位");
                } else {
                    et_title_search.setHint("搜索求购车位");
                }
            }
            et_title_search.setText(keyWords);
            currentPage = 1;
            sendRequest(PriceID);
        }
    }


    /**
     * 获取筛选条件
     */
    private void getConditionLimit() {
        try {
            mRequest = NoHttp.createStringRequest(Urls.BASE_JAVA_URL+"system/getLimit", LrConstant.POST);
            mRequest.add("type",1);
            // 添加到请求队列+
            CallServer.getRequestInstance().add(this, mRequest,
                    new CustomJavaHttpListener<ConditionBean>(this, true, ConditionBean.class) {
                        @Override
                        public void doWork(ConditionBean data, int code) {
                            List<ConditionBean.ModelBean> modelBeans = data.getModel();
                            List<FiltrateConditionBean> list = new ArrayList<>();
                            for (int i = 0; i < modelBeans.size(); i++) {
                                list.add(new FiltrateConditionBean(true,modelBeans.get(i).getDesc()));
                                for (int j = 0; j < modelBeans.get(i).getData().size(); j++) {
                                    ConditionBean.ModelBean.DataBean cmd = modelBeans.get(i).getData().get(j);
                                    list.add(new FiltrateConditionBean(new FiltrateBean
                                            (modelBeans.get(i).getKey(),cmd.getValue(),cmd.getTxt(),false)));
                                }


                            }
                            filtrateData.clear();
                            filtrateData.addAll(list);
                            //filtrateAdapter.notifyDataSetChanged();


                        }

                        @Override
                        public void onFinally(String obj, int code, boolean isSucceed) throws JSONException {
                            super.onFinally(obj, code, isSucceed);

                        }
                    }, false);
        } catch (Exception e) {
        }
    }
    private void sendRequest (int PriceID) {
        getDealData(PriceID,areaId,dealType,keyWords,orderByWay,currentPage);
    }
    /**
     * 获取列表数据
     */
    private void getDealData(int PriceID,int areaId, String type, String keys, int orderBy, final int page ) {
        try {
            mRequest = NoHttp.createStringRequest(Urls.IP_SHOW, LrConstant.POST);
            mRequest.add("action", "GetShowInfoTable");
            mRequest.add("uid", AppConfig.getInstance().getString("uid", ""));
            mRequest.add("phonePara", Application.DEVICE_ID);
            mRequest.add("pageIndex", page);
            if (areaId == 0) {
                mRequest.add("cityName", AppConfig.getInstance().getString("strCity", ""));
            } else {
                if (isCity) {
                    mRequest.add("cityId", areaId);
                } else {
                    mRequest.add("areaId", areaId);
                }
            }
            mRequest.add("type", type);
            mRequest.add("PriceID",PriceID);
            mRequest.add("spaceOwnerType",0);
            mRequest.add("SpaceType",spaceType);
            mRequest.add("keyWord", keys);
            mRequest.add("orderBy", orderBy);
            if (paramsMap!= null && paramsMap.size() > 0) {
                for (Object key:paramsMap.keySet()
                        ) {
                    List<String> value = (List<String>) paramsMap.get(key);
                    String values = value.toString();
                    String result =  values.replaceAll("\\[","").replaceAll("]","")
                            .replaceAll(" ","");
                    mRequest.add((String) key,result);
                }
            }
            // 添加到请求队列+
            CallServer.getRequestInstance().add(this, mRequest,
                    new CustomHttpListener<StallListBean>(this, true, StallListBean.class) {
                        @Override
                        public void doWork(StallListBean data, String code) {
                            if (TextUtils.equals("1", code)) {
                                if (adapter != null) {
                                    if (data != null && data.getData().size() != 0) {
                                        empty.setVisibility(View.GONE);
                                        if (page == 1) {
                                            list = data.getData();
                                            adapter.setNewData(data.getData());
                                        } else {
                                            list.addAll(data.getData());
                                            adapter.notifyDataSetChanged();
                                        }
                                        adapter.loadMoreComplete();
                                    } else {

                                        if (page == 1) {
                                            list.clear();
                                            adapter.notifyDataSetChanged();
                                            empty.setVisibility(View.VISIBLE);
                                        } else {
                                            adapter.loadMoreEnd();
                                        }
                                    }
                                }
                            } else {
                                ToastUtils.showShort(data.getMsg()+"");
                            }
                        }
                        @Override
                        public void onFinally(JSONObject obj, String code, boolean isSucceed) {
                            if (swipeRefreshLayout != null) {
                                swipeRefreshLayout.endRefreshing();
                            }


                        }
                    }, false);
        } catch (Exception e) {
        }
    }


    /**
     * 获取运营城市和市区列表
     */
    private void getCityList() {
        //
        try {
            mRequest = NoHttp.createStringRequest(Urls.RUNNING_CITY_URL, LrConstant.GET);
            // 添加到请求队列+
            CallServer.getRequestInstance().add(this, mRequest,
                    new HttpListener<String>() {
                        @Override
                        public void onSucceed(int what, Response<String> response) {
                            String json = response.get();
                            ArrayList<PopCityJson> jsonBean = parseData(json);
                            cityBeen = new ArrayList<>();
                            areaBeen = new ArrayList<>();
                            String city = AppConfig.getInstance().getString("strCity","郑州市");
                            for (int i=0;i<jsonBean.size();i++){
                                if (jsonBean.get(i).getName().equals(city) || jsonBean.get(i).getName().contains(city)) {
                                    cityBeen.add(new CityBean(jsonBean.get(i).getId(),jsonBean.get(i).getId(),jsonBean.get(i).getName()));
                                if (jsonBean.get(i).getAreas()== null || jsonBean.get(i).getAreas().size()==0){
                                    List<CityBean> di = new ArrayList<>();
                                    di.add(new CityBean(jsonBean.get(i).getId(),jsonBean.get(i).getId(),"全地区"));
                                    areaBeen.add(di);
                                } else {
                                    List<CityBean> cityArr = new ArrayList<>();
                                    cityArr.add(new CityBean(jsonBean.get(i).getId(),jsonBean.get(i).getId(),"全地区"));
                                    int length = jsonBean.get(i).getAreas().size();
                                    for (int c=0; c< length; c++){
                                        if (!jsonBean.get(i).getAreas().get(c).getName().equals("市辖区")) {
                                            cityArr.add(new CityBean(jsonBean.get(i).getId(),jsonBean.get(i).getAreas().get(c).getId(),jsonBean.get(i).getAreas().get(c).getName()));
                                        }
                                    }
                                    areaBeen.add(cityArr);
                                    break;
                                }
                                }
                            }
                            initPop();
                        }

                        @Override
                        public void onFailed(int what, Response<String> response) {

                        }
                    }, false);
        } catch (Exception e) {
        }
    }
    private ArrayList<PopCityJson> parseData(String result) {
        ArrayList<PopCityJson> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                PopCityJson entity = gson.fromJson(data.optJSONObject(i).toString(), PopCityJson.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return detail;
    }

    /**
     * 地区初始化
     */
    private void initPop() {
        View view = View.inflate(this,R.layout.pop_window_layout,null);
        initPopView(view);
        check_city.setPopupView(view,800);
    }

    private void initPopView(View mView) {
        rvCity = (RecyclerView) mView.findViewById(R.id.rv_city);
        rvArea = (RecyclerView) mView.findViewById(R.id.rv_area);
        initRecyclerView(rvCity);
        initRecyclerView(rvArea);
        adapter1 = new PopChoseCityAdapter(cityBeen);
        rvCity.setAdapter(adapter1);
        adapter2 = new PopChoseCityAdapter(selectOfCity);
        rvArea.setAdapter(adapter2);
        adapter1.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                adapter1.setPressPostion(position);
                adapter1.notifyDataSetChanged();
                selectOfCity =areaBeen.get(position);
                adapter2.setPressPostion(-1);
                adapter2.setNewData(selectOfCity);
            }
        });

        adapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                adapter2.setPressPostion(position);
                adapter2.notifyDataSetChanged();
                CityBean data =selectOfCity.get(position);
                check_city.setText(data.getName());
                check_city.hidePopup();
                areaId = data.getId();
                selectCityId = data.getCityId();
                currentPage = 1;
                if (selectCityId == areaId) {
                    isCity = true;
                } else {
                    isCity = false;
                }
                sendRequest(PriceID);
            }
        });
        adapter1.setPressPostion(0);
        adapter1.notifyDataSetChanged();
        adapter2.setPressPostion(0);
        if (areaBeen.size() != 0) {
            selectOfCity = areaBeen.get(0);
            adapter2.setNewData(areaBeen.get(0));
            adapter2.notifyDataSetChanged();
        }
    }

    private void initRecyclerView(RecyclerView recyclerView) {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    /**
     * 价格初始化
     */
    private void initPricePop() {
        View view = View.inflate(this,R.layout.pop_stall_chuzu_list,null);
        initPricePopView(view);
        if (dealType.equals("20")) {
            check_price.setPopupView(view, 650);
        } else if (dealType.equals("21")) {
            check_price.setPopupView(view, 800);
        }
    }


    /**
     * 获取筛选价格条件
     * @param type
     */
    private void getSpacePriceFilter(String type){
        try {
            mRequest = NoHttp.createStringRequest(Urls.IP_SHOW, LrConstant.POST);
            mRequest.add("action", "GetSpacePriceFilter");
            mRequest.add("type",type);
            CallServer.getRequestInstance().add(baseContext, mRequest,
                    new CustomHttpListener<SpacePriceFilterM>(baseContext, true, SpacePriceFilterM.class) {
                        @Override
                        public void doWork(SpacePriceFilterM data, String code) {
                            if (code.equals("1")) {
                                strstallprice=data.getData();
                                initPricePop();
                            }
                        }

                        @Override
                        public void onFinally(JSONObject obj, String code, boolean isSucceed) {
                            try {
                                super.onFinally(obj, code, isSucceed);
                                if (!code.equals("1")) {
                                    ToastUtils.showShort(obj.getString("msg"));
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }, false);
        } catch (Exception e) {

        }

    }

    private void initPricePopView(View mView) {
        rv_stall_chuzu_list=(ListView) mView.findViewById(R.id.rv_stall_chuzu_list);
        stallpriceAdapter=new StallPriceAdapter(this,strstallprice);
        rv_stall_chuzu_list.setAdapter(stallpriceAdapter);
        rv_stall_chuzu_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                stallpriceAdapter.setSelectPosition(position);
                check_price.setText(strstallprice.get(position).getTitle());
                check_price.hidePopup();
                currentPage = 1;
                PriceID=strstallprice.get(position).getID();
                sendRequest(PriceID);
            }
        });
    }

    private void getCarPlaceType() {
        try {
            mRequest = NoHttp.createStringRequest(Urls.SPACE_IP, LrConstant.POST);
            mRequest.add("action", "GetSpaceType");
            CallServer.getRequestInstance().add(baseContext, mRequest,
                    new CustomHttpListener<AddStallTypeBean>(baseContext, true, AddStallTypeBean.class) {
                        @Override
                        public void doWork(AddStallTypeBean data, String code) {
                            if (code.equals("1")) {
                                for (int i = 0; i < data.getData().size(); i++) {
                                    carType1.add(new CarPlaceTypeMode(data.getData().get(i).getKey()
                                            ,data.getData().get(i).getValue()));
                                    ArrayList<CarPlaceTypeMode> type1 = new ArrayList<>();
                                    for (int j = 0; j < data.getData().get(i).getData().size(); j++) {
                                        type1.add(new CarPlaceTypeMode
                                                (data.getData().get(i).getData().get(j).getKey(),data.getData().get(i).getData().get(j).getValue()));
                                    }
                                    carType2.add(type1);
                                }
                                initstallTypePop();
                            }
                        }
                        @Override
                        public void onFinally(JSONObject obj, String code, boolean isSucceed) {
                            try {
                                super.onFinally(obj, code, isSucceed);
                                if (!code.equals("1")) {
                                    ToastUtils.showShort(obj.getString("msg"));
                                }
                            } catch (Exception e) {

                            }
                        }
                    }, true);
        } catch (Exception e) {

        }
    }
    /**
     * 车位类型初始化
     */
    private void initstallTypePop() {
        View view = View.inflate(this,R.layout.pop_window_layout,null);
        initstallTypePopView(view);
        check_type.setPopupView(view,800);
    }

    private void initstallTypePopView(View mView) {
        rvCity = (RecyclerView) mView.findViewById(R.id.rv_city);
        rvArea = (RecyclerView) mView.findViewById(R.id.rv_area);
        initRecyclerView(rvCity);
        initRecyclerView(rvArea);
        popStallAdapter1 = new PopStallAdapter(carType1);
        rvCity.setAdapter(popStallAdapter1);
        popStallAdapter2 = new PopStallAdapter(selectcarType);
        rvArea.setAdapter(popStallAdapter2);

        popStallAdapter1.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                popStallAdapter1.setPressPostion(position);
                popStallAdapter1.notifyDataSetChanged();
                selectcarType =carType2.get(position);
                popStallAdapter2.setPressPostion(-1);
                popStallAdapter2.setNewData(selectcarType);
            }
        });

        popStallAdapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                popStallAdapter2.setPressPostion(position);
                popStallAdapter2.notifyDataSetChanged();
                String data =selectcarType.get(position).getValue();
                spaceType = selectcarType.get(position).getKey();
                check_type.setText(data);
                check_type.hidePopup();
                currentPage = 1;
                sendRequest(PriceID);
            }
        });

        popStallAdapter1.setPressPostion(0);
        popStallAdapter1.notifyDataSetChanged();
        popStallAdapter2.setPressPostion(0);
        if (carType2.size() != 0) {
            selectcarType = carType2.get(0);
            popStallAdapter2.setNewData(carType2.get(0));
            popStallAdapter2.notifyDataSetChanged();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
